package com.isunland.managesystem.ui;

import android.support.test.espresso.ViewInteraction;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.isunland.managesystem.R;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
import static android.support.test.espresso.action.ViewActions.replaceText;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withClassName;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withParent;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.is;

@LargeTest @RunWith(AndroidJUnit4.class) public class SignTest {

  @Rule public ActivityTestRule<SplashActivity> mActivityTestRule =
      new ActivityTestRule<>(SplashActivity.class);

  @Test public void signTest() {
    ViewInteraction appCompatEditText = onView(allOf(withId(R.id.username), isDisplayed()));
    appCompatEditText.perform(replaceText("wangk@ft"), closeSoftKeyboard());
    ViewInteraction appCompatEditText2 = onView(allOf(withId(R.id.password), isDisplayed()));
    appCompatEditText2.perform(replaceText("123456"), closeSoftKeyboard());

    ViewInteraction appCompatButton =
        onView(allOf(withId(R.id.login), withText("登录"), isDisplayed()));
    appCompatButton.perform(click());

    ViewInteraction linearLayout = onView(allOf(withId(R.id.ll_sign_everyday), isDisplayed()));
    linearLayout.perform(click());

    ViewInteraction appCompatButton2 =
        onView(allOf(withId(R.id.bt_sign_in), withText("签到"), isDisplayed()));
    appCompatButton2.perform(click());

    ViewInteraction appCompatButton3 = onView(allOf(withId(android.R.id.button2), withText("继续打卡"),
        withParent(allOf(withClassName(is("com.android.internal.widget.ButtonBarLayout")),
            withParent(withClassName(is("android.widget.LinearLayout"))))), isDisplayed()));
    appCompatButton3.perform(click());

    ViewInteraction appCompatButton4 = onView(allOf(withId(android.R.id.button1), withText("确定"),
        withParent(allOf(withClassName(is("com.android.internal.widget.ButtonBarLayout")),
            withParent(withClassName(is("android.widget.LinearLayout"))))), isDisplayed()));
    appCompatButton4.perform(click());
  }
}
